#include "DataStructure/Input/Element/CBARData.h"

#include <vector>

#include "Utility/Algebra/Vector3D.h"

#include "DataStructure/Common/Validation.h"
#include "DataStructure/Input/Element/BeamCoordOptions.h"
#include "DataStructure/Input/Solver/DOFDirections.h"

using namespace SG::DataStructure::FEM;

/** @brief 朝向矢量，节点1和节点2 偏置矢量所在坐标系
 *
 */
std::vector<BeamCoordOptions> CBARData::GetCoordOptions () const
{
    return SG::DataStructure::FEM::GetBeamCoordOptions (m_flag);
};

/**  @brief 获取节点1的释放自由度
 *
 */
DofSet CBARData::GetDofSetOfPaRelease () const
{
    return Int2VDofSet (m_pa);
}

/**  @brief 获取节点2的释放自由度
 *
 */
DofSet CBARData::GetDofSetOfPbRelease () const
{
    return Int2VDofSet (m_pb);
}

/** @brief 获取节点1的偏移量
 */
SG::Algebra::Vector3D CBARData::GetWa () const
{
    return SG::Algebra::Vector3D{ m_w1a, m_w2a, m_w3a };
}

/** @brief 获取节点1的偏移量
 */
SG::Algebra::Vector3D CBARData::GetWb () const
{
    return SG::Algebra::Vector3D{ m_w1b, m_w2b, m_w3b };
}

/// @brief 判断两个CBARData是否相等
/// @param a
/// @param b
/// @return
bool SG::DataStructure::FEM::operator== (const CBARData& a, const CBARData& b)
{
    if (a.m_id != b.m_id)
    {
        return false;
    }
    if (a.m_pId != b.m_pId)
    {
        return false;
    }
    if (a.m_g[0] != b.m_g[0])
    {
        return false;
    }
    if (a.m_g[1] != b.m_g[1])
    {
        return false;
    }
    if (a.m_flag != b.m_flag)
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_x1, b.m_x1))
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_x2, b.m_x2))
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_x3, b.m_x3))
    {
        return false;
    }
    if (a.m_go != b.m_go)
    {
        return false;
    }
    if (a.m_pa != b.m_pa)
    {
        return false;
    }
    if (a.m_pb != b.m_pb)
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_w1a, b.m_w1a))
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_w2a, b.m_w2a))
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_w3a, b.m_w3a))
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_w1b, b.m_w1b))
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_w2b, b.m_w2b))
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_w3b, b.m_w3b))
    {
        return false;
    }
    if (a.m_domainId != b.m_domainId)
    {
        return false;
    }
    return true;
}
